<template>
  <el-menu
      class="el-menu-vertical-demo"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      router
  >
    <router-link to="/home">
      <el-menu-item index="Home">
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </template>
      </el-menu-item>
    </router-link>
    <el-submenu :index="menu.name" v-for="(menu, index) in menuList" :key="index">
      <template slot="title">
        <i :class="menu.icon"></i>
        <span>{{menu.name}}</span>
      </template>
        <el-menu-item :index="item.url" v-for="(item, index2) in menu.children" :key="index2">
          <template slot="title">
            <i :class="item.icon"></i>
            <span slot="title">{{item.name}}</span>
          </template>
        </el-menu-item>
    </el-submenu>
  </el-menu>
</template>
<script>
export default {
  name: "SideMenu",
  data() {
    return {
      menuList: []
    }
  },
  created() {
    this.getSideMenus()
  },
  methods: {
    selectMenu(item) {
      this.$store.commit("addTab", item)
    },
    getSideMenus() {
      this.$http.get('/sys/menu/nav').then(res => {
        this.menuList = res.data.data.nav
        window.sessionStorage.setItem("permList", res.data.data.authorities)
        // this.menuList.forEach(x => {
        //   x.children.forEach(item => {
        //     const routeObj = {
        //       path: item.url,
        //       name: item.name,
        //       meta: {
        //         title: item.name,
        //         noCache: true
        //       },
        //       component: () => import(`../modules/${item.component}.vue`)
        //     }
        //     this.$router.addRoute('Main', routeObj)
        //   })
        // })
      })
    }
  }
}
</script>
<style scoped>
.el-menu-vertical-demo {
  height: 100%;
}
a{
  text-decoration:none;
}
.el-menu {
  border-right: none;
}
</style>
